package com.cloudfun.campusshare.util;

import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.cloudfun.campusshare.common.constant.HeatStatus;
import org.apache.commons.lang.math.NumberUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by Huqin on 2020/4/20
 */
public class WasherControlUtil {

    private static final List<WasherControlVO> WASHER_CTRL_LIST = new ArrayList<>();

    static {
        WASHER_CTRL_LIST.add(new WasherControlVO("1", HeatStatus.HEAT_OFF, false, false, "1"));
        WASHER_CTRL_LIST.add(new WasherControlVO("2", HeatStatus.HEAT_OFF, false, false, "2"));
        WASHER_CTRL_LIST.add(new WasherControlVO("3", HeatStatus.HEAT_OFF, false, false, "3"));
        WASHER_CTRL_LIST.add(new WasherControlVO("4", HeatStatus.HEAT_OFF, false, false, "4"));
        WASHER_CTRL_LIST.add(new WasherControlVO("5", HeatStatus.HEAT_OFF, false, false, "5"));
        WASHER_CTRL_LIST.add(new WasherControlVO("8", HeatStatus.HEAT_OFF, false, false, "8"));

        WASHER_CTRL_LIST.add(new WasherControlVO("1", HeatStatus.HEAT_OFF, false, true, "106"));
        WASHER_CTRL_LIST.add(new WasherControlVO("2", HeatStatus.HEAT_OFF, false, true, "107"));
        WASHER_CTRL_LIST.add(new WasherControlVO("3", HeatStatus.HEAT_OFF, false, true, "108"));
        WASHER_CTRL_LIST.add(new WasherControlVO("8", HeatStatus.HEAT_OFF, false, true, "109"));

        WASHER_CTRL_LIST.add(new WasherControlVO("1", HeatStatus.HEAT_OFF, true, true, "110"));
        WASHER_CTRL_LIST.add(new WasherControlVO("2", HeatStatus.HEAT_OFF, true, true, "111"));
        WASHER_CTRL_LIST.add(new WasherControlVO("3", HeatStatus.HEAT_OFF, true, true, "112"));

        WASHER_CTRL_LIST.add(new WasherControlVO("1", HeatStatus.HEAT_OFF, true, false, "113"));
        WASHER_CTRL_LIST.add(new WasherControlVO("2", HeatStatus.HEAT_OFF, true, false, "114"));
        WASHER_CTRL_LIST.add(new WasherControlVO("3", HeatStatus.HEAT_OFF, true, false, "115"));

        WASHER_CTRL_LIST.add(new WasherControlVO("1", HeatStatus.HEAT_40, false, false, "116"));
        WASHER_CTRL_LIST.add(new WasherControlVO("2", HeatStatus.HEAT_40, false, false, "117"));
        WASHER_CTRL_LIST.add(new WasherControlVO("3", HeatStatus.HEAT_40, false, false, "118"));


        WASHER_CTRL_LIST.add(new WasherControlVO("1", HeatStatus.HEAT_40, false, true, "119"));
        WASHER_CTRL_LIST.add(new WasherControlVO("2", HeatStatus.HEAT_40, false, true, "120"));
        WASHER_CTRL_LIST.add(new WasherControlVO("3", HeatStatus.HEAT_40, false, true, "121"));


        WASHER_CTRL_LIST.add(new WasherControlVO("1", HeatStatus.HEAT_60, false, false, "122"));
        WASHER_CTRL_LIST.add(new WasherControlVO("2", HeatStatus.HEAT_60, false, false, "123"));
        WASHER_CTRL_LIST.add(new WasherControlVO("3", HeatStatus.HEAT_60, false, false, "124"));


        WASHER_CTRL_LIST.add(new WasherControlVO("1", HeatStatus.HEAT_60, false, true, "125"));
        WASHER_CTRL_LIST.add(new WasherControlVO("2", HeatStatus.HEAT_60, false, true, "126"));
        WASHER_CTRL_LIST.add(new WasherControlVO("3", HeatStatus.HEAT_60, false, true, "127"));
    }

    /**
     * 获取滚筒洗衣机洗衣程序
     *
     * @param washType
     * @param heat40
     * @param heat60
     * @param speedUpStatus    加强洗
     * @param quietRinseStatus 超净漂洗
     * @return
     */
    public static String getWasherWashType(String washType, boolean heat40, boolean heat60, boolean speedUpStatus, boolean quietRinseStatus) {
        HeatStatus heatStatus;
        if (heat40 || heat60) {
            heatStatus = heat40 ? HeatStatus.HEAT_40 : HeatStatus.HEAT_60;
        } else {
            heatStatus = HeatStatus.HEAT_OFF;
        }
        List<String> retWashTypes = WASHER_CTRL_LIST.stream()
                .filter(washerControlVO -> washerControlVO.getWashType().equals(washType))
                .filter(washerControlVO -> heatStatus == washerControlVO.getHeatStatus())
                .filter(washerControlVO -> speedUpStatus == washerControlVO.isSpeedUpStatus())
                .filter(washerControlVO -> quietRinseStatus == washerControlVO.isQuietRinseStatus())
                .map(WasherControlVO::getResWashType)
                .collect(Collectors.toList());
        if (CollectionUtils.isEmpty(retWashTypes) || retWashTypes.size() > NumberUtils.INTEGER_ONE) {
            return null;
        }
        return retWashTypes.get(0);
    }
}